package com.deer.wms.ureport.web;

import com.deer.wms.ureport.model.Test2;
import com.deer.wms.ureport.model.Test2Criteria;
import com.deer.wms.ureport.service.Test2Service;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.deer.wms.project.root.core.result.Result;
import com.deer.wms.project.root.core.result.ResultGenerator;

import java.util.List;

/**
* Created by  on 2021/02/04.
*/
@RestController
@RequestMapping("/test2s")
public class Test2Controller {

    @Autowired
    private Test2Service test2Service;

    @PostMapping("/add")
    public Result add(@RequestBody Test2 test2) {
        test2Service.save(test2);
        return ResultGenerator.genSuccessResult();
    }

    @GetMapping("/delete")
    public Result delete(  Integer id) {
        test2Service.removeById(id);
        return ResultGenerator.genSuccessResult();
    }

    @PostMapping("/update")
    public Result update(@RequestBody Test2 test2) {
        test2Service.updateById(test2);
        return ResultGenerator.genSuccessResult();
    }

    @GetMapping("/{id}")
    public Result detail(@PathVariable Integer id) {
        Test2 test2 = test2Service.getById(id);
        return ResultGenerator.genSuccessResult(test2);
    }

    @GetMapping("/list")
    public Result list(Test2Criteria criteria) {
        PageHelper.startPage(criteria.getPageNum(), criteria.getPageSize());
        List<Test2> list = test2Service.list();
        PageInfo pageInfo = new PageInfo(list);
        return ResultGenerator.genSuccessResult(pageInfo);
    }

}
